package hhb.game.zhualaoer.core.dao;

import hhb.game.zhualaoer.core.enums.Rank;
import hhb.game.zhualaoer.core.enums.Suit;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@Getter
@Setter
public class Card implements Comparable<Card>{
    private final Suit suit;
    private final Rank rank;

    public Card(Suit suit, Rank rank) {
        this.suit = suit;
        this.rank = rank;
    }

    // 按点数比较（用于排序）
    public int compareTo(Card other) {
        //先比较点数，在比较花色
        //比较点数
        int compare = Integer.compare(this.rank.getValue(), other.rank.getValue());
        if (compare != 0) {
            return compare;
        }else{
            //比较花色
            return this.suit.compareTo(other.suit);
        }
    }

    // 按点数和花色比较（用于判断相同点数时的大小）
    public int compareToWithRank(Card other) {
        return Integer.compare(this.rank.getValue(), other.rank.getValue());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return suit == card.suit && rank == card.rank;
    }

    @Override
    public int hashCode() {
        return Objects.hash(suit, rank);
    }

    @Override
    public String toString() {
        return suit.getSymbol() + rank.name(); // 示例输出：♠ACE, ♥TEN
    }
}
